package com.jrtc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jrtc.base.entity.bo.Family;
import com.jrtc.dao.FamilyDao;
import com.jrtc.service.FamilyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 患者家属表(Family)表服务实现类
 *
 * @author makejava
 * @since 2022-03-21 17:34:12
 */
@Service("familyService")
public class FamilyServiceImpl implements FamilyService
{
    @Resource
    private FamilyDao familyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param familyId 主键
     * @return 实例对象
     */
    @Override
    public Family queryById(Integer familyId) {
        return this.familyDao.queryById(familyId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Family> queryAllByLimit(int offset, int limit) {
        return this.familyDao.queryAllByLimit(offset, limit);
    }

    @Override
    public IPage<Family> queryFamilyList(Family family)
    {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<Family> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(family.getPageNo(), family.getPageSize());
        IPage<Family> familyPage = this.familyDao.queryFamilyList(page, family);
        return familyPage;
    }
    /**
     * 新增数据
     *
     * @param family 实例对象
     * @return 实例对象
     */
    @Override
    public Family insert(Family family) {
        this.familyDao.insert(family);
        return family;
    }

    /**
     * 修改数据
     *
     * @param family 实例对象
     * @return 实例对象
     */
    @Override
    public Family update(Family family) {
        this.familyDao.update(family);
        return this.queryById(family.getFamilyId());
    }

    /**
     * 通过主键删除数据
     *
     * @param familyId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer familyId) {
        return this.familyDao.deleteById(familyId) > 0;
    }
}